<template>
	<view class="log">
		<view class="clock_in">
			<view class="left">
				<view class="complete_clock_in">
					<text class="num">{{dayNum}}</text>
					<text class="day">天</text>
				</view>
				<view class="complete_clock_in_text">本月已打卡</view>
			</view>
			<view class="right">
				<image src="/static/img/log/fenxiang.png" mode="" @click="shareClick"></image>
				<image src="/static/img/log/xuanze.png" mode=""></image>
			</view>
		</view>
		<view class="all">
			<view class="all_title">
				<text>全年</text>
				<text class="num">
					<text>{{yearNum}}天</text>
					<text style="color:#939393"> > </text>
				</text>
			</view>
			<view class="day_num">
				<view class="item" v-for="item in 365" :key="item" :class="{item_light: item < yearNum}"></view>
			</view>
		</view>
		<uni-calendar 
			:insert="true"
			:lunar="false" 
			:start-date="'2000-3-2'"
			:end-date="current"
			@change="change"
			:selected="logData"
			:showMonth="false"
			 />
			 
			 <tab-bar></tab-bar>
	</view>
</template>

<script>
	import { motionLog, queryStatistics } from '../../service/api.js'
	import TabBar from '../../components/TabBar.vue'
	export default {
		components: { TabBar },
		data() {
			return {
				year: null,  //当前年份
				month: null, //当前月份
				
				dayNum: 0, //本月打卡
				yearNum: 0, //全年打卡
				
				current: "", //当前年月日
				
				logData: [], //打卡数据
			}
		},
		onLoad() {
			this.$nextTick(() => {
				const date = new Date();
				const year = date.getFullYear();
				const month = date.getMonth() + 1;
				const day = date.getDate();
				
				const current = `${year}-${month}-${day}`;
				this.current = current;
				this.year = year;
				this.month = month;
				
				this.getMotionLog();
				this.getQueryStatistics()
			})
		
		},
		methods: {
			//全年打卡和本月打开
			getQueryStatistics() {
				const params = {
					year: this.year,
					month: this.month
				}
				//本月
				queryStatistics(params).then(res => {
					if(res.status == 200) {
						this.dayNum = res.data;
					}
				})
				//全年
				queryStatistics({year: this.year}).then(res => {
					if(res.status == 200) {
						this.yearNum = res.data;
					}
				})
			},
			getMotionLog() {
				motionLog(this.year).then(res => {
					if(res.status == 200) {
						this.logData = res.data.map(item => ({
							date: `${item.year}-${item.month}-${item.day}`,
							info: "打卡"
						}));
					}
				})
			},
			change(e) {
				// console.log(e)
			},
			shareClick() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 1,
					summary: "我正在使用运动, 紧跟我一起来体验吧！",
					success: function (res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function (err) {
						console.log("fail:" + JSON.stringify(err));
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
::v-deep .uni-calendar-item__weeks-box-item {
	> .uni-calendar-item__weeks-box-circle {
		background-color: #5ED3C8;
	}
	> .uni-calendar-item__weeks-lunar-text {
		color:  #5ED3C8;
	}
}

.log {
	padding: 0 40rpx;
	overflow: hidden;
	.all {
		padding-top: 40rpx;
		overflow: hidden;
		.all_title {
			color: #9F9F9F;
			display: flex;
			justify-content: space-between;
			padding-bottom: 12rpx;
			.num {
				color: #3C3C3C;
			}
		}
		.day_num {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			&::after {
				content: "";
				flex: auto;
			}
			.item {
				width: 8rpx;
				height: 16rpx;
				background-color: #D6E0DF;
				margin: 4rpx;
				
			}
			
			.item_light {
				background-color: #24B6A8;
			}
		}
		// .day_num::after {
		// 	content: "";
		// 	width: 8rpx;
		// }
		
	}
	
	.clock_in {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 40rpx;
		.left {
			
			.complete_clock_in {
				.num {
					color: #24B6A8;
					font-size: 60rpx;
				} 
				.day {
					color: #9F9F9F;
					margin-left: 4rpx;
				}
			}
			.complete_clock_in_text {
				color: #515151;
			}
		}
		.right {
			display: flex;
			align-items: center;
			image {
				width: 56rpx;
				height: 60rpx;
				margin-left: 40rpx;
			}
			image:last-child {
				height: 48rpx;
			}
		}
	}
}
</style>
